<?php

namespace App\Model\Device;

use App\Model\Face\FaceModel;
use App\Model\System\WxConfig;
use App\Model\Admin\User;

class DeviceModel extends \App\Model\BaseModel
{

	public $tableName = "sc_device";

	/**
	 * 通过条件获取数据库里面的设备
	 * @auth   xiaozhi
	 * @param  array   $field [description]
	 * @param  array   $where [description]
	 * @param  array   $page [description]
	 * @param  array   $limit [description]
	 * @param  array   $order [description]
	 * @return [type]             [description]
	 */
	public function getDeviceData($field = '*', $where = [],  $page = 1, $pageSize =10, $order = ['A.id', 'desc'])
    {
		$this->withTotalCount()
		    ->field($field)
		    ->order($order[0], $order[1])
		    ->alias('A')
			->join('sc_device_info as B', 'A.id = B.devid', 'LEFT')
			->where($where)
            ->page($page, $pageSize)
            ->all();

		$count = $this->lastQueryResult()->getTotalCount();
        $lists = $this->lastQueryResult()->getResult();

        return ['count' => $count, 'lists' => $lists];
	}

	/**
	 * 获取单个设备和设备详情列表
	 */
	public function getDeviceInfo($field = '*', $where = [])
    {
		$this->field($field)
			->alias('A')
			->join('sc_device_info as B', 'A.id = B.devid', 'LEFT')
			->where($where)
			->get();

		$result = $this->lastQueryResult()->getResult();

		if ($result) {
			return $result[0];
		} else {
			return false;
		}
	}

}